<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Globalize::Locale</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Globalize::Locale</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/plugins/globalize/lib/globalize/localization/locale_rb.html">
                vendor/plugins/globalize/lib/globalize/localization/locale.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
<a href="Locale.html">Locale</a> defines the currenctly <a
href="Locale.html#M000034">active</a> <em>locale</em>. You&#8216;ll mostly
use it like this:
</p>
<pre>
  Locale.set(&quot;en-US&quot;)
</pre>
<p>
<tt>en</tt> is the code for English, and <tt>US</tt> is the <a
href="Locale.html#M000040">country</a> code. The <a
href="Locale.html#M000040">country</a> code is optional, but you&#8216;ll
need to define it to get a lot of the localization features.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000034">active</a>&nbsp;&nbsp;
      <a href="#M000031">active?</a>&nbsp;&nbsp;
      <a href="#M000037">base?</a>&nbsp;&nbsp;
      <a href="#M000036">base_language</a>&nbsp;&nbsp;
      <a href="#M000033">clear_cache</a>&nbsp;&nbsp;
      <a href="#M000040">country</a>&nbsp;&nbsp;
      <a href="#M000038">language</a>&nbsp;&nbsp;
      <a href="#M000039">language_code</a>&nbsp;&nbsp;
      <a href="#M000042">new</a>&nbsp;&nbsp;
      <a href="#M000032">set</a>&nbsp;&nbsp;
      <a href="#M000035">set_base_language</a>&nbsp;&nbsp;
      <a href="#M000045">set_pluralized_translation</a>&nbsp;&nbsp;
      <a href="#M000043">set_translation</a>&nbsp;&nbsp;
      <a href="#M000044">set_translation_with_namespace</a>&nbsp;&nbsp;
      <a href="#M000041">switch_locale</a>&nbsp;&nbsp;
      <a href="#M000046">translator</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">code</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">country</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">currency_code</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">currency_decimal_sep</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">currency_format</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">date_format</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">decimal_sep</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">language</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">number_grouping_scheme</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">thousands_sep</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000034" class="method-detail">
        <a name="M000034"></a>

        <div class="method-heading">
          <a href="#M000034" class="method-signature">
          <span class="method-name">active</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Locale.html#M000034">active</a> locale.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000034-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 49</span>
49:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">active</span>; <span class="ruby-ivar">@@active</span> <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000031" class="method-detail">
        <a name="M000031"></a>

        <div class="method-heading">
          <a href="#M000031" class="method-signature">
          <span class="method-name">active?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Is there an <a href="Locale.html#M000034">active</a> locale?
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000031-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 27</span>
27:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">active?</span>; <span class="ruby-operator">!</span><span class="ruby-ivar">@@active</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000037" class="method-detail">
        <a name="M000037"></a>

        <div class="method-heading">
          <a href="#M000037" class="method-signature">
          <span class="method-name">base?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Is the currently <a href="Locale.html#M000034">active</a> <a
href="Locale.html#M000038">language</a> the base language?
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000037-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 77</span>
77:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">base?</span>
78:       <span class="ruby-identifier">active</span> <span class="ruby-value">? </span><span class="ruby-identifier">active</span>.<span class="ruby-identifier">language</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">base_language</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">true</span>
79:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000036" class="method-detail">
        <a name="M000036"></a>

        <div class="method-heading">
          <a href="#M000036" class="method-signature">
          <span class="method-name">base_language</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the base <a href="Locale.html#M000038">language</a>. Raises an
exception if none is <a href="Locale.html#M000032">set</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000036-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 69</span>
69:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">base_language</span>
70:       <span class="ruby-ivar">@@base_language</span> <span class="ruby-operator">?</span> <span class="ruby-ivar">@@base_language</span> <span class="ruby-operator">:</span>
71:         (<span class="ruby-ivar">@@base_language_code</span> <span class="ruby-operator">?</span>
72:         (<span class="ruby-ivar">@@base_language</span> = <span class="ruby-constant">Language</span>.<span class="ruby-identifier">pick</span>(<span class="ruby-ivar">@@base_language_code</span>)) <span class="ruby-operator">:</span>
73:         <span class="ruby-identifier">raise</span>(<span class="ruby-constant">NoBaseLanguageError</span>, <span class="ruby-value str">&quot;base language must be defined&quot;</span>))
74:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000033" class="method-detail">
        <a name="M000033"></a>

        <div class="method-heading">
          <a href="#M000033" class="method-signature">
          <span class="method-name">clear_cache</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Clears the locale cache &#8212; used mostly for testing.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000033-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 44</span>
44:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">clear_cache</span>
45:       <span class="ruby-ivar">@@cache</span>.<span class="ruby-identifier">clear</span>
46:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000040" class="method-detail">
        <a name="M000040"></a>

        <div class="method-heading">
          <a href="#M000040" class="method-signature">
          <span class="method-name">country</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the currently <a href="Locale.html#M000034">active</a> <a
href="Locale.html#M000040">country</a> model or <tt>nil</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000040-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 92</span>
92:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">country</span>
93:       <span class="ruby-identifier">active?</span> <span class="ruby-value">? </span><span class="ruby-identifier">active</span>.<span class="ruby-identifier">country</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
94:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000038" class="method-detail">
        <a name="M000038"></a>

        <div class="method-heading">
          <a href="#M000038" class="method-signature">
          <span class="method-name">language</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the currently <a href="Locale.html#M000034">active</a> <a
href="Locale.html#M000038">language</a> model or <tt>nil</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000038-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 82</span>
82:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">language</span>
83:       <span class="ruby-identifier">active?</span> <span class="ruby-value">? </span><span class="ruby-identifier">active</span>.<span class="ruby-identifier">language</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
84:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000039" class="method-detail">
        <a name="M000039"></a>

        <div class="method-heading">
          <a href="#M000039" class="method-signature">
          <span class="method-name">language_code</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the currently <a href="Locale.html#M000034">active</a> <a
href="Locale.html#M000038">language</a> code or <tt>nil</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000039-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 87</span>
87:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">language_code</span>
88:       <span class="ruby-identifier">active?</span> <span class="ruby-value">? </span><span class="ruby-identifier">language</span>.<span class="ruby-identifier">code</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
89:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000042" class="method-detail">
        <a name="M000042"></a>

        <div class="method-heading">
          <a href="#M000042" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(code)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a <a href="Locale.html#M000042">new</a> locale object by looking up
an RFC 3066 code in the database.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000042-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 116</span>
116:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">code</span>)
117:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">code</span>.<span class="ruby-identifier">nil?</span>
118:         <span class="ruby-keyword kw">return</span>
119:       <span class="ruby-keyword kw">end</span>
120: 
121:       <span class="ruby-identifier">rfc</span> = <span class="ruby-constant">RFC_3066</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">code</span>)
122:       <span class="ruby-ivar">@code</span> = <span class="ruby-identifier">rfc</span>.<span class="ruby-identifier">locale</span>
123: 
124:       <span class="ruby-ivar">@language</span> = <span class="ruby-constant">Language</span>.<span class="ruby-identifier">pick</span>(<span class="ruby-identifier">rfc</span>)
125:       <span class="ruby-ivar">@country</span> = <span class="ruby-constant">Country</span>.<span class="ruby-identifier">pick</span>(<span class="ruby-identifier">rfc</span>)
126: 
127:       <span class="ruby-identifier">setup_fields</span>
128:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000032" class="method-detail">
        <a name="M000032"></a>

        <div class="method-heading">
          <a href="#M000032" class="method-signature">
          <span class="method-name">set</span><span class="method-args">(locale)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
This is the focal point of the class. Sets the locale in the familiar RFC
3066 format (see: <a
href="http://www.faqs.org/rfcs/rfc3066.html">www.faqs.org/rfcs/rfc3066.html</a>).
It can also take a <a href="Locale.html">Locale</a> object. Set it to the
<tt>nil</tt> object, to deactivate the locale.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000032-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 33</span>
33:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">locale</span>)
34:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Locale</span>
35:         <span class="ruby-ivar">@@active</span> = <span class="ruby-identifier">locale</span>
36:       <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">nil?</span>
37:         <span class="ruby-ivar">@@active</span> = <span class="ruby-keyword kw">nil</span>
38:       <span class="ruby-keyword kw">else</span>
39:         <span class="ruby-ivar">@@active</span> = ( <span class="ruby-ivar">@@cache</span>[<span class="ruby-identifier">locale</span>] <span class="ruby-operator">||=</span> <span class="ruby-constant">Locale</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">locale</span>) )
40:       <span class="ruby-keyword kw">end</span>
41:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000035" class="method-detail">
        <a name="M000035"></a>

        <div class="method-heading">
          <a href="#M000035" class="method-signature">
          <span class="method-name">set_base_language</span><span class="method-args">(lang)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the base <a href="Locale.html#M000038">language</a>. The base <a
href="Locale.html#M000038">language</a> is the <a
href="Locale.html#M000038">language</a> that has complete coverage in the
database. For instance, if you have a <tt>Category</tt> model with a
<tt>name</tt> field, the base <a href="Locale.html#M000038">language</a> is
the <a href="Locale.html#M000038">language</a> in which names are stored in
the model itself, and not in the translations table.
</p>
<p>
Takes either a <a href="Locale.html#M000038">language</a> code (valid RFC
3066 code like <tt>en</tt> or <tt>en-US</tt>) or a <a
href="Locale.html#M000038">language</a> object.
</p>
<p>
May be <a href="Locale.html#M000032">set</a> with a <a
href="Locale.html#M000038">language</a> code in environment.rb, without
accessing the db.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000035-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 60</span>
60:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">set_base_language</span>(<span class="ruby-identifier">lang</span>)
61:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">lang</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Language</span>
62:         <span class="ruby-ivar">@@base_language</span> = <span class="ruby-identifier">lang</span>
63:       <span class="ruby-keyword kw">else</span>
64:         <span class="ruby-ivar">@@base_language_code</span> = <span class="ruby-constant">RFC_3066</span>.<span class="ruby-identifier">parse</span> <span class="ruby-identifier">lang</span>
65:       <span class="ruby-keyword kw">end</span>
66:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000045" class="method-detail">
        <a name="M000045"></a>

        <div class="method-heading">
          <a href="#M000045" class="method-signature">
          <span class="method-name">set_pluralized_translation</span><span class="method-args">(key, idx, translation, namespace = nil, language = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000045-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 172</span>
172:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">set_pluralized_translation</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">idx</span>, <span class="ruby-identifier">translation</span>, <span class="ruby-identifier">namespace</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">language</span> = <span class="ruby-keyword kw">nil</span>)
173:       <span class="ruby-identifier">language</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">language</span>
174:                         <span class="ruby-identifier">translator</span>.<span class="ruby-identifier">set_pluralized</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">language</span>, <span class="ruby-identifier">idx</span>, <span class="ruby-identifier">translation</span>, <span class="ruby-identifier">namespace</span>)
175:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000043" class="method-detail">
        <a name="M000043"></a>

        <div class="method-heading">
          <a href="#M000043" class="method-signature">
          <span class="method-name">Locale.set_translation(key, language, *translations)<br />
Locale.set_translation(key, *translations)<br />
</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the translation for <tt>key</tt>.
</p>
<p>
If <tt><a href="Locale.html#M000038">language</a></tt> is given, define a
translation using that <a href="Locale.html#M000038">language</a> model,
otherwise use the <a href="Locale.html#M000034">active</a> <a
href="Locale.html#M000038">language</a>.
</p>
<p>
Multiple translation strings may be given, in order to define plural forms.
In English, there are only two plural forms, singular and plural, so you
would provide two strings at the most. The order is determined by the
formula in the languages database. For English, the order is: singular
form, then plural.
</p>
<p>
Example:
</p>
<pre>
  Locale.set_translation(&quot;There are %d items in your cart&quot;,
  &quot;There is one item in your cart&quot;, &quot;There are %d items in your cart&quot;)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000043-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 148</span>
148:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">set_translation</span>(<span class="ruby-identifier">key</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">options</span>)
149:       <span class="ruby-identifier">key</span>, <span class="ruby-identifier">language</span>, <span class="ruby-identifier">translations</span>, <span class="ruby-identifier">zero_form</span> = <span class="ruby-identifier">key_and_language</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">options</span>)
150:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;No translations given&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">empty?</span>
151:       <span class="ruby-identifier">translator</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">language</span>, <span class="ruby-identifier">translations</span>, <span class="ruby-identifier">zero_form</span>, <span class="ruby-keyword kw">nil</span>)
152:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000044" class="method-detail">
        <a name="M000044"></a>

        <div class="method-heading">
          <a href="#M000044" class="method-signature">
          <span class="method-name">set_translation_with_namespace</span><span class="method-args">(key, namespace, *options)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Same as <a href="Locale.html#M000043">set_translation</a> but translation
is <a href="Locale.html#M000032">set</a> to a particular namespace
</p>
<p>
Example:
</p>
<pre>
  Locale.set('es-ES')
  Locale.set_translation(&quot;draw&quot;, &quot;dibujar&quot;)
  &quot;draw&quot;.t =&gt; &quot;dibujar&quot;
  Locale.set_translation_with_namespace(&quot;draw&quot;, &quot;lottery&quot;, &quot;seleccionar&quot;)
  &quot;draw&quot; &gt;&gt; 'lottery' =&gt; &quot;seleccionar&quot;
</pre>
<p>
or
</p>
<pre>
  Locale.set_translation(&quot;draw %d times&quot;, &quot;dibujar una vez&quot;, &quot;dibujar %d veces&quot;)
  Locale.set_translation_with_namespace(&quot;draw %d times&quot;, &quot;lottery&quot;, &quot;seleccionar una vez&quot;, &quot;seleccionar %d veces&quot;)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000044-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 166</span>
166:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">set_translation_with_namespace</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">namespace</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">options</span>)
167:       <span class="ruby-identifier">key</span>, <span class="ruby-identifier">language</span>, <span class="ruby-identifier">translations</span>, <span class="ruby-identifier">zero_form</span> = <span class="ruby-identifier">key_and_language</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">options</span>)
168:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;No translations given&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">empty?</span>
169:       <span class="ruby-identifier">translator</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">language</span>, <span class="ruby-identifier">translations</span>, <span class="ruby-identifier">zero_form</span>, <span class="ruby-identifier">namespace</span>)
170:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000041" class="method-detail">
        <a name="M000041"></a>

        <div class="method-heading">
          <a href="#M000041" class="method-signature">
          <span class="method-name">switch_locale</span><span class="method-args">(code) {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Allows you to switch the current locale while within the block. The
previously current locale is reset after the block is finished.
</p>
<p>
e.g
</p>
<pre>
    Locale.set('en-US')
    Locale.switch_locale('es-ES') do
      product.name = 'esquis'
    end

    product.name
    &gt; skis
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000041-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 107</span>
107:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">switch_locale</span>(<span class="ruby-identifier">code</span>)
108:       <span class="ruby-identifier">current_locale</span> = <span class="ruby-constant">Locale</span>.<span class="ruby-identifier">active</span>
109:       <span class="ruby-constant">Locale</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">code</span>)
110:       <span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">yield</span>
111:       <span class="ruby-constant">Locale</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">current_locale</span>.<span class="ruby-identifier">code</span>)
112:       <span class="ruby-identifier">result</span>
113:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000046" class="method-detail">
        <a name="M000046"></a>

        <div class="method-heading">
          <a href="#M000046" class="method-signature">
          <span class="method-name">translator</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Locale.html#M000046">translator</a> object &#8212;
mostly for testing and adjusting the cache.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000046-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/localization/locale.rb, line 184</span>
184:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">translator</span>; <span class="ruby-ivar">@@translator</span> <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>